﻿using System;
using System.IO;
using System.Linq;
using Dokan;

namespace CueMounter.DokanStructure
{
	partial class DokanDirectoryOperations
	{
		private void FillFileInformation(DokanFile file, FileInformation fileInfo)
		{
			if(file.CanWrite)
			{
				fileInfo.Attributes = FileAttributes.Normal;
			}
			else
			{
				fileInfo.Attributes = FileAttributes.ReadOnly;
			}

			fileInfo.CreationTime = file.Dates.CreateTime;
			fileInfo.LastAccessTime = file.Dates.AccessTime;
			fileInfo.LastWriteTime = file.Dates.ModifyTime;

			fileInfo.FileName = file.Name;
			fileInfo.Length = file.Length;
		}

		private void FillDirectoryFileInformation(string name, FileInformation fileInfo)
		{
			fileInfo.FileName = name;
			fileInfo.Attributes = FileAttributes.Directory;
			fileInfo.CreationTime = fileInfo.LastAccessTime = fileInfo.LastWriteTime = DateTime.Now;
			fileInfo.Length = 0;
		}

		private void FillDirectoryFileInformation(DokanDirectory dir, FileInformation fileInfo)
		{
			fileInfo.FileName = dir.Name;
			fileInfo.Attributes = FileAttributes.Directory;
			fileInfo.CreationTime = dir.Dates.CreateTime;
			fileInfo.LastAccessTime = dir.Dates.AccessTime;
			fileInfo.LastWriteTime = dir.Dates.ModifyTime;
			fileInfo.Length = 0;
		}


		private FileInformation CreateDirectoryFileInformation(string name)
		{
			var info = new FileInformation();
			FillDirectoryFileInformation(name, info);
			return info;
		}

		private FileInformation CreateDirectoryFileInformation(DokanDirectory dir)
		{
			var info = new FileInformation();
			FillDirectoryFileInformation(dir, info);
			return info;
		}

		private FileInformation CreateFileInformation(DokanFile file)
		{
			var info = new FileInformation();
			FillFileInformation(file, info);
			return info;
		}
	}
}
